package com.hxzy.service.impl;

import com.hxzy.entity.TbPanelContent;
import com.hxzy.mapper.TbPanelContentMapper;
import com.hxzy.service.TbPanelContentService;
import com.hxzy.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TbPanelContentServiceImpl implements TbPanelContentService {
    @Override
    public TbPanelContent selectByPrimaryKey(Integer id) {
        TbPanelContent tbPanelContent=null;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelContentMapper mapper = session.getMapper(TbPanelContentMapper.class);
            tbPanelContent=mapper.selectByPrimaryKey(id);
        }
        return tbPanelContent;
    }

    @Override
    public boolean insert(TbPanelContent record) {
        int count=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelContentMapper mapper = session.getMapper(TbPanelContentMapper.class);
            count=mapper.insert(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public boolean updateByPrimaryKey(TbPanelContent record) {
        int count=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelContentMapper mapper = session.getMapper(TbPanelContentMapper.class);
            count=mapper.updateByPrimaryKey(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public boolean updateByPrimaryKeySelective(TbPanelContent record) {
        int count=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelContentMapper mapper = session.getMapper(TbPanelContentMapper.class);
            count=mapper.updateByPrimaryKeySelective(record);
            session.commit();
        }
        return count>0;
    }

    @Override
    public List<TbPanelContent> search() {
        List<TbPanelContent> search=null;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelContentMapper mapper = session.getMapper(TbPanelContentMapper.class);
            search = mapper.search();
        }
        return search;
    }

    @Override
    public List<TbPanelContent> searchByCondition(TbPanelContent tbPanelContent) {
        List<TbPanelContent> list;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbPanelContentMapper mapper = session.getMapper(TbPanelContentMapper.class);
            list = mapper.searchByCondition(tbPanelContent);
        }
        return list;
    }
}
